package View;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.HelperHtml;
import model.Tour;
import model.TourDAO;

/**
 * Servlet implementation class DetailTour
 */
@WebServlet("/DetailTour")
public class DetailTour extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetailTour() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("utf-8");
		String ID=request.getParameter("MaTour");
		response.getWriter().write(HelperHtml.getHtml(LoadData(ID)));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	private String LoadData(String ID) {
		String s="";
		TourDAO da= new TourDAO();
		Tour t=da.getTourByID(ID);
		s+="<div id='Detail'>";
		//s+="<img width='125' height='100' src='images/"+t.getImage()+"' id='imageTour'style='float: left;' />";
		s+="<h3><strong>"+t.getTentour()+"</strong></h3>";
		s+="<p><b>Thời gian: </b>"+t.getThoigian()+"</p>";
		s+="<p><b>Điểm khỏi hành: </b>"+t.getDiemkhoihanh()+"</p>";
		s+="<p><b>Giá Tour: </b>"+t.getGia()+"</p>";
		s+="<p><h3>Lịch trình Tour:</h3></p>";
		s+="<p>"+t.getNoidung()+"</p>";
		s+="<p><h3>Giá Tour bao gồm:</h3></p>";
		s+="<p>"+t.getBaogom()+"</p>";
		s+="<p><h3>Giá Tour không bao gồm:</h3></p>";
		s+="<p>"+t.getKhongbaogom()+"</p>";
		s+="<p><h3>Giá dành cho trẻ em:</h3></p>";
		s+="<p>"+t.getGiachotreem()+"</p>";
		s+="<form style='text-align: center;' action='Booking?Matour="+ID+"'><input id='btnBooking' type='submit' value='Đặt Tour'> </input></form>";
		s+="</div>";
		return s;
	}
}
